const Bundler = require('parcel-bundler');
const views = require('koa-views');
const stc = require('koa-static');
const { resolve } = require('path');

const abPath = path => resolve(__dirname, path);

// 配置 parcel-bundler
const bundler = new Bundler(abPath('../../../src/index.html'), {
    publicURL: './',
    watch: true
})

/**
 * 开发环境 development
 * @param {*} app 
 */
export const dev = async app => {
    await bundler.bundle();
    // 配置静态web服务的中间件
    app.use(stc(abPath('../../../dist')));

    // // 配置视图中间件
    // app.use(views(abPath('../../../dist')), {
    //     extension: 'html'
    // });

    // app.use(async ctx => {
    //     ctx.type = 'text/html';
    //     console.log(`url: ${ctx.url}`);
    //     console.log(`originalUrl: ${ctx.originalUrl}`);
    //     console.log(`path: ${ctx.path}`);
    //     console.log(`href: ${ctx.href}`);
    //     await ctx.render('index.html');
    // })
}